package pro.softzhang.algo.lc900;

import pro.softzhang.algo.flag.knowledge.KMonotonicStack;
import pro.softzhang.algo.flag.theme.TStock;

import java.util.Stack;

@TStock
public class LC901_OnlineStockSpan {
    public static void main(String[] args) {

    }

    @KMonotonicStack
    static
    class StockSpanner {

        private Stack<int[]> stack;

        private int idx = 0;

        public StockSpanner() {
            stack = new Stack<>();
        }

        public int next(int price) {
            while (!stack.isEmpty() && stack.peek()[1] <= price) stack.pop();
            int prev = stack.isEmpty() ? -1 : stack.peek()[0], days = idx - prev;
            stack.push(new int[]{idx++, price});
            return days;
        }
    }

}
